function toggleLogin(){
	$('nav_user_login').style.display=='none'?Element.show('nav_user_login'):Element.hide('nav_user_login');
}
function v(){
}

function legalJargon(page) {
	if(typeof(page)=='undefined')page='../media.threadless.com/submitterms.html';
	var x = (screen.width/2) - 175;
	var y = (screen.height/2) - 225;
	var newWin = window.open(page,'legal','width=570,height=450,left='+x+',top='+y+',screenX='+x+',screenY='+y+',status=1,scrollbars=1');
	newWin.opener.name = "threadless";
}

var varidbuyit = 'notset';
function score(id,action,current,hash){
	if(action=='buy'){
		if(varidbuyit=='notset')varidbuyit=current;
		$('idbuyit').src='../media.threadless.com/imgs/score_buyit'+(varidbuyit==0?'_o':'')+'.gif';
		varidbuyit=(varidbuyit==0?1:0);
	}else{
		$('scorechunk').innerHTML='<img src="../media.threadless.com/imgs/loading.gif" align="absmiddle"> Saving...';
		var myAjax = new Ajax.Request('../media.threadless.com/scripts/quicksub.php',{method: 'post', parameters: "id="+id+"&score="+action+"&idbuyit="+varidbuyit+"&hash="+hash, onComplete: score_done});
	}
}

function score_done(originalRequest){
	$('scorechunk').innerHTML= originalRequest.responseText;	
	
	valid.deactivate();
}


function showProd(id,title, bordercolor){
	Position.prepare();
	coords = Position.cumulativeOffset($('product_'+id));
	$('overlay_piece').style.left=coords[0]+'px';
	$('overlay_piece').style.top=coords[1]+'px';
	$('overlay_piece').innerHTML='<div style="background-color:#fff;width:198px;height:188px;"><div style="padding:2px;border:2px solid #'+bordercolor+';width:190px;height:180px;"><a onmouseout="hideProd()" href="../media.threadless.com/product/'+id+'/'+title+'"><img src="../media.threadless.com/product/190x180/'+id+'-minizoom.jpg" width="190" height="180"/></a></div></div>';
	Element.show('overlay_piece');
}
function hideProd(){
	Element.hide('overlay_piece');
}

function crit(id,current,hash){
	$('crit_'+id+'_1').src='../media.threadless.com/imgs/crit1.gif';
	$('crit_'+id+'_2').src='../media.threadless.com/imgs/crit2.gif';
	$('crit_'+id+'_3').src='../media.threadless.com/imgs/crit3.gif';
	$('crit_'+id+'_'+current).src='../media.threadless.com/imgs/crit'+current+'_o'+'.gif';
	var superAjax = new Ajax.Updater('crit_'+id+'_graph',"../media.threadless.com/scripts/critgraph.php",{method: 'get', parameters: "&id="+id+"&choice="+current+"&hash="+hash});	
}

function type_score(id,score,hash){
	$('slogan_load_'+id).innerHTML='<img src="../media.threadless.com/imgs/loading.gif" style="margin-left:5px;margin-bottom:6px;">';
	setTimeout(function(){$('slogan_load_'+id).innerHTML=''},1000);
	$('slog'+id+'_no').src='../media.threadless.com/imgs/omg_no'+(score==0?'_r':'')+'.gif';
	$('slog'+id+'_wear').src='../media.threadless.com/imgs/omg_wear'+(score==1?'_r':'')+'.gif';
	var myAjax = new Ajax.Request('../media.threadless.com/scripts/slogans.rate.php',{method: 'get', parameters: "justscore=1&hash="+hash+"&sloganid="+id+"&rating="+(score==1?'yes':'no')});
}

var currentid;
function showStock(id){
	if(id!=currentid){
		Position.prepare();
		coords = Position.cumulativeOffset($('product_'+id));
		$('overlay_piece').style.left=coords[0]+168+'px';
		$('overlay_piece').style.top=coords[1]-10+'px';
		$('overlay_piece').innerHTML='<div id="stock_loading"></div>';
		Element.show('overlay_piece');
		var superAjax = new Ajax.Updater('overlay_piece',"../media.threadless.com/scripts/ministockvert.php",{method: 'get', parameters: "&id="+id});	
		currentid=id;
	}else{
		Element.hide('overlay_piece');
		currentid='';
	}
}
var currentid;
function showQuick(id){
	if(id!=currentid){
		Position.prepare();
		coords = Position.cumulativeOffset($('sub_'+id));
		$('overlay_piece').style.left=coords[0]-16+'px';
		$('overlay_piece').style.top=coords[1]+'px';
		$('overlay_piece').innerHTML='<div id="quick_piece"><a href="../media.threadless.com/scripts/quicksub.php@id='+id+'" class="lbOn"></a></div>';
		initialize();
		Element.show('overlay_piece');
		currentid=id;
	}
}  


   function scoreOver(score){
	$('s'+score).src='../media.threadless.com/imgs/score/'+score+'_r.gif@x=5';
   }
   function scoreOut(score){
   	if(typeof(window['currentscore']) != "undefined" && score!=currentscore){
		$('s'+score).src='../media.threadless.com/imgs/score/'+score+'.gif@x=5';
	}
   }
   function clickArrow(score){
	if(currentscore!='notset'){
		removescore=currentscore;
		currentscore=score;
		scoreOut(removescore);
	}
	currentscore=score;
	showArrow(score);
   }
function showArrow(score){ 
	var contentOffset = $j(".contentMain").offset();
	//alert(contentOffset.left+" - "+contentOffset.top);
	var offset = $j("#s"+score).offset();
	$j("#myscore").css("left",(offset.left-contentOffset.left-24)+"px");
	$j("#myscore").css("top",(offset.top-contentOffset.top-10)+"px");
	/*$('s'+score).src='../media.threadless.com/imgs/score/'+score+'_r.gif';
   	Position.prepare();
   	coords = Position.cumulativeOffset($('s'+score));
   	$('myscore').style.left=(coords[0])+'px';
   	$('myscore').style.top=(coords[1])+'px';*/
	$('myscore').style.display='';
}

   var varidbuytee = 'notset';
   var varidbuyprint = 'notset';
   function scoreSub(id,action,current,hash){
   	if(action=='buytee'){
   		if(varidbuytee=='notset')varidbuytee=current;
   		$('idbuytee').src='../media.threadless.com/imgs/score/buy_tee'+(varidbuytee==0?'_on':'')+'.gif';
   		varidbuytee=(varidbuytee==0?1:0);
   	}else if(action=='buyprint'){            	
   		if(varidbuyprint=='notset')varidbuyprint=current;
   		$('idbuyprint').src='../media.threadless.com/imgs/score/buy_print'+(varidbuyprint==0?'_on':'')+'.gif';
   		varidbuyprint=(varidbuyprint==0?1:0);
   	}else{
   		$('scorechunk').innerHTML='<img src="../media.threadless.com/imgs/loading.gif" align="absmiddle"> Saving...';
   		var myAjax = new Ajax.Request('../media.threadless.com/scripts/quicksub.php',{method: 'post', parameters: "id="+id+"&score="+action+"&idbuyprint="+varidbuyprint+"&idbuyit="+varidbuytee+"&hash="+hash, onComplete: scoreSubDone});
   	}
   }
   
   function scoreSubDone(originalRequest){
   	$('scorechunk').innerHTML= originalRequest.responseText;	
   	valid.deactivate();
   }

function showQuick2(id){
	if(id!=currentid){
		Position.prepare();
		coords = Position.cumulativeOffset($('sub_'+id));
		$('overlay_piece').style.left=coords[0]-16+'px';
		$('overlay_piece').style.top=coords[1]+'px';
		$('overlay_piece').innerHTML='<div id="quick_piece"><a href="../media.threadless.com/scripts/quicksubnew.php@id='+id+'" class="lbOn"></a></div>';
		initialize();
		Element.show('overlay_piece');
		currentid=id;
	}
}
function hideQuick(){
	Element.hide('overlay_piece');
	currentid=0;
}

var currentstockid;
function reprint_show(stockid){
	if(stockid!=currentstockid){
		Position.prepare();
		coords = Position.cumulativeOffset($('reprintme_'+stockid));
		$('reprint_overlay').style.left=coords[0]-15+'px';
		$('reprint_overlay').style.top=coords[1]-160+'px';
		$('reprint_overlay').innerHTML='<img src="../media.threadless.com/imgs/loading.gif" align="absmiddle"> Loading...';
		Element.show('reprint_overlay');
		var thisAjax = new Ajax.Updater('reprint_overlay',"../media.threadless.com/scripts/reprintform.php",{method: 'get', parameters: "&id="+stockid});	
		currentstockid=stockid;
	}else{
		Element.hide('reprint_overlay');
		currentstockid='';
	}	
}

var currentproductid;
function reprint_product(productid, containerId, x, y ){
    var container = ( containerId != null ) ? 'reprint_overlay' + containerId : 'reprint_overlay';

    if ( x == null ) {
        x = 15;
    }
    if ( y == null ) {
        y = 160;
    }
	
	if(productid!=currentproductid){
		Position.prepare();
		coords = Position.cumulativeOffset($j( container ));
		if ( x > 0 ) {
		    $( container ).style.left=coords[0] - x + 'px';
		}
		if ( y > 0 ) {
		    $( container ).style.top=coords[1] - y + 'px';
		}

		$( container ).innerHTML='<img src="../media.threadless.com/imgs/loading.gif" align="absmiddle"> Loading...';
		Element.show(container);
		var thisAjax = new Ajax.Updater( container,"../media.threadless.com/scripts/reprintform.php",{method: 'get', parameters: "&containerId="+ containerId +"&productid="+productid});	
		currentproductid=productid;
	}else{
		Element.hide( container );
		currentproductid='';
	}	
}

function reprint(id,emails){
	$('reprint_overlay').innerHTML='<img alt=\"Loading...\" src=\"../media.threadless.com/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> Saving your request...';	
	var superAjax = new Ajax.Updater('reprint_overlay',"../media.threadless.com/scripts/reprintform.php",{method: 'post', parameters: "&id="+id+"&emails="+emails});		
}
function reprint_simple(id,emails, containerId ){
    var container = ( containerId != null ) ? 'reprint_overlay' + containerId : 'reprint_overlay';
    var joinNewsletter = $('join_newsletter').checked;

	$(container).innerHTML='<img alt=\"Loading...\" src=\"../media.threadless.com/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> Saving your request...';	
	var params = "&containerId="+ containerId +"&productid="+id+"&emails="+emails;
	if ( joinNewsletter == true ) {
	    params += '&joinNewsletter=1';
	}
	var superAjax = new Ajax.Updater( container,"../media.threadless.com/scripts/reprintform.php",{method: 'post', parameters: params});		
}

function add_to_cart(stockid){
	Position.prepare();
	coords = Position.cumulativeOffset($('add'+stockid));
	$('add_overlay').style.left=coords[0]-15+'px';
	$('add_overlay').style.top=coords[1]-180+'px';
	$('add_overlay').innerHTML='<img src="../media.threadless.com/imgs/loading.gif" align="absmiddle"> Loading...';
	Element.show('add_overlay');
	var thisAjax = new Ajax.Updater('add_overlay',"../media.threadless.com/scripts/add_to_cart.php",{method: 'get', parameters: "&id="+stockid});	
	return false;
}

function enterPromo(id){
	$('promo'+id).innerHTML='<img alt=\"Loading...\" src=\"../media.threadless.com/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> Counting you in...';	
	var superAjax = new Ajax.Updater('promo'+id,"../media.threadless.com/scripts/enterpromo.php",{method: 'post', parameters: "&id="+id });		
}
function tellafriend(id,emails){
	$('tellafriend').innerHTML='<img alt=\"Loading...\" src=\"../media.threadless.com/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> Sending email(s)...';	
	var superAjax = new Ajax.Updater('tellafriend',"../media.threadless.com/scripts/tellafriend.php",{method: 'post', parameters: "&id="+id+"&emails="+emails});		
}

/*---
Favorites Stuff
---*/
function watchToggle(type,id){
	url = "../media.threadless.com/scripts/watch.php";
	pars = "&id="+id+"&type="+type;
	
	if(type!='bf')$('fave_'+id).innerHTML="<img alt=\"Loading...\" src=\"../media.threadless.com/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\">";
	else $('fave_'+id).innerHTML="<img alt=\"Loading...\" src=\"../media.threadless.com/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> &nbsp; <span class=\"grey\">Please wait</span>";
	var myAjax = new Ajax.Updater(
		'fave_'+id,
		url, 
		{method: 'post', parameters: pars}
		);
}

function showPhoto(type,id,object){
	//$('product_photo').innerHTML="<img alt=\"Loading...\" src=\"../media.threadless.com/imgs/loading.gif\" width=\"18\" height=\"18\" align=\"absmiddle\"> &nbsp; Loading...";
	object.className='selected';
	if(type=='photo') {
		if(id >= photoArray.length) id = 0;
		else if(id < 0) id = photoArray.length-1;			
		photoIndex=id;
		id = photoArray[id];
	}
	var superAjax = new Ajax.Updater('product_photo',"../media.threadless.com/scripts/productphoto.php",{method: 'get', parameters: "&type="+type+"&id="+id});	
}

function loadPresence(id){
	flickr_url = "../media.threadless.com/scripts/profile_flickr.php";
	flickr_pars = "&id="+id;
	var flickrAjax = new Ajax.Updater('profile_flickr',flickr_url,{method: 'post', parameters: flickr_pars}	)
	
	delicious_url = "../media.threadless.com/scripts/profile_delicious.php";
	delicious_pars = "&id="+id;
	var deliciousAjax = new Ajax.Updater('profile_delicious',delicious_url,{method: 'post', parameters: delicious_pars}	)
	
	lastfm_url = "../media.threadless.com/scripts/profile_lastfm.php";
	lastfm_pars = "&id="+id;
	var lastfmAjax = new Ajax.Updater('profile_lastfm',lastfm_url,{method: 'post', parameters: lastfm_pars}	)

	myspace_url = "../media.threadless.com/scripts/profile_myspace.php";
	myspace_pars = "&id="+id;
	var myspaceAjax = new Ajax.Updater('profile_myspace',myspace_url,{method: 'post', parameters: myspace_pars}	);	
		
	rssentries_url = "../media.threadless.com/scripts/profile_rss.php";
	rssentries_pars = "&id="+id;
	var rssentriesAjax = new Ajax.Updater('profile_rss',rssentries_url,{method: 'post', parameters: rssentries_pars}	)
}


function showTab(show){
	$(show).style.display='';
	$('nav_'+show).className='active';
	var args = showTab.arguments;	  
	for (var i = 1; i < args.length; i++) {		
		$(args[i]).style.display='none';
		$('nav_'+args[i]).className = $('nav_'+args[i]).className.replace('active','');
	}
	
} 


var form_submitted = false;

function isDoubleSubmit ( msg )
{
  if ( form_submitted )
  {
    alert ( msg );
    return false;
  }
  else
  {
    form_submitted = true;
    return true;
  }
}
